package com.yj.lottery_system.dao.mapper;

import com.yj.lottery_system.dao.dataObject.ActivityUserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    /**
     * 批量插入信息
     * @param activityUserDOList
     * @return
     */
    @Insert("<script> " +
            "insert into activity_user  " +
            "(activity_id, user_id, user_name, status) " +
            "values <foreach item = 'item' collection='items' index='index' separator=','  > " +
            " (#{item.activityId},#{item.userId},#{item.userName},#{item.status}) " +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int batchInsert(@Param("items")List<ActivityUserDO> activityUserDOList);

    /**
     * 根据活动id 查活动关联人员信息
     * @param activityId
     * @return
     */
    @Select("select * from activity_user where  activity_id = #{activityId}")
    List<ActivityUserDO> selectByActivityId(@Param("activityId") Long activityId);

    @Select("<script> " +
            "select * from  activity_user  " +
            "where activity_id = #{activityId}  and " +
            "user_id in" +
            "<foreach collection = 'userIds' item = 'userId' open='(' separator=',' close=')'> " +
            "#{userId}" +
            "</foreach>" +
            "</script>")
    List<ActivityUserDO> batchSelectByAUId(@Param("activityId")Long activityId,
                                           @Param("userIds")List<Long> userIds);

    @Update("<script> " +
            "update activity_user set status = #{status}" +
            "where activity_id = #{activityId}  and " +
            "user_id in" +
            "<foreach collection = 'userIds' item = 'userId' open='(' separator=',' close=')'> " +
            "#{userId}" +
            "</foreach>" +
            "</script>")
    void batchUpdateStatus(@Param("activityId")Long activityId,
                                   @Param("userIds")List<Long> userIds,
                                   @Param("status") String status) ;
}
